/*
  (C) 2007 - Boston University
  Contact: Michael Ocean 

	this file was adapted from a CS511 submission

  This work is a part of the larger snBench project.  Information
  can be found at: http://csr.bu.edu/snbench 

  This program is free software; you can redistribute it and/or
  modify it under the terms of Version 2 of the GNU General Public 
  License.
  
  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  General Public License for more details.
  
  You should have received a copy of the GNU Library General Public
  License along with this library; if not, write to the Free
  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package stepide;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JWindow;
/**
 * Splash screen for SDE.
 * 
 * @author Miran Badzak
 * @author Szu Han Chang
 * @author Kevin Hu
 */

public class SplashScreen extends JWindow {
	
	final static long serialVersionUID = 1L;
	
	/**
	 * Default constructor.
	 *
	 */
	public SplashScreen() {	}

	/**
	 * Display the splash screen.
	 *
	 */
	
	private JProgressBar pbar = new JProgressBar();
	
	public void showSplash() {
		
		pbar.setMinimum(0);
		pbar.setMaximum(100);
		
		JPanel content = (JPanel)getContentPane();
		content.setBackground(Color.LIGHT_GRAY);

		// set the window's bounds, centering the window
		int width = 450;
		int height = 115;
		Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
		int x = (screen.width-width)/2;
		int y = (screen.height-height)/2;
		setBounds(x,y,width,height);

		// build the splash screen
		JLabel label = new JLabel("Loading the STEP Development Environment...", JLabel.CENTER);
		label.setFont(new Font("Sans-Serif", Font.BOLD, 14));
		
		content.add(label, BorderLayout.CENTER);
		content.add(pbar, BorderLayout.SOUTH);

		content.setBorder(BorderFactory.createLineBorder(new Color(155,155,155), 7));

		// display it
		setVisible(true);
		/*
		for (int i = 0; i < 100; i++){
			final int percent=i;
		       try {
		         SwingUtilities.invokeLater(new Runnable() {
		             public void run() {
		               pbar.setValue(percent);
		             }
		         });
		         java.lang.Thread.sleep(20);
		       } catch (InterruptedException e) {;}
		}

		setVisible(false);
		*/
	}

	
	public void update(int percent){
		pbar.setValue(percent);
	}
	
	public void showSplashAndExit() {
		showSplash();
		System.exit(0);
	}
}